package com.taobao.ui.widget;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

import com.taobao.action.ColumnAction;
import com.taobao.action.ui.MouseRightAction;
import com.taobao.pojo.Receive;
import com.taobao.pojo.Task;
import com.taobao.tools.Binding;
import com.taobao.ui.menu.CommonMenu;

public class ReceiveTaskWidget extends CommonWidget {
	public static final String ID = "com.taobao.ui.widget.ReceiveTaskWidget";
	private Table table;

	@Override
	public String getID() {
		return ReceiveTaskWidget.ID;
	}

	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public ReceiveTaskWidget(Composite parent, int style) {
		super(parent, style);
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.marginWidth = 0;
		gridLayout.marginHeight = 0;
		setLayout(gridLayout);

		table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		table.setMenu(new CommonMenu(table));
		table.addMouseListener(new MouseRightAction(new ColumnAction(), getThis(ReceiveTaskWidget.class), table));
		Binding.binding(getThis(ReceiveTaskWidget.class), table, Binding.GROUP_LIST, Receive.class, "receiveTasks");

		TableColumn tableColumn = new TableColumn(table, SWT.NONE);
		tableColumn.setWidth(40);
		tableColumn.setText("\u5E8F\u53F7");
		tableColumn.setToolTipText("no");

		TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
		tableColumn_1.setWidth(150);
		tableColumn_1.setText("\u4EFB\u52A1\u7F16\u53F7");
		tableColumn_1.setToolTipText("id");

		TableColumn tableColumn_2 = new TableColumn(table, SWT.NONE);
		tableColumn_2.setWidth(154);
		tableColumn_2.setText("\u53D1\u5E03\u4EBA");
		tableColumn_2.setToolTipText("name");

		TableColumn tableColumn_3 = new TableColumn(table, SWT.NONE);
		tableColumn_3.setWidth(100);
		tableColumn_3.setText("\u6DD8\u5B9D\u8D26\u53F7");
		tableColumn_3.setToolTipText("tbName");

		TableColumn tableColumn_4 = new TableColumn(table, SWT.NONE);
		tableColumn_4.setWidth(53);
		tableColumn_4.setText("\u53D1\u5E03\u70B9");
		tableColumn_4.setToolTipText("publishPoint");

		TableColumn tableColumn_5 = new TableColumn(table, SWT.NONE);
		tableColumn_5.setWidth(100);
		tableColumn_5.setText("\u4EFB\u52A1\u4EF7\u683C");
		tableColumn_5.setToolTipText("price");

		TableColumn tableColumn_6 = new TableColumn(table, SWT.NONE);
		tableColumn_6.setWidth(150);
		tableColumn_6.setText("\u53D1\u5E03\u65F6\u95F4");
		tableColumn_6.setToolTipText("publishTime");

		TableColumn tableColumn_7 = new TableColumn(table, SWT.NONE);
		tableColumn_7.setWidth(100);
		tableColumn_7.setText("\u63A5\u624B\u5C0F\u53F7");
		tableColumn_7.setToolTipText("smallUser");

		TableColumn tableColumn_8 = new TableColumn(table, SWT.NONE);
		tableColumn_8.setWidth(150);
		tableColumn_8.setText("\u72B6\u6001");
		tableColumn_8.setToolTipText("state");

		TableColumn tableColumn_9 = new TableColumn(table, SWT.NONE);
		tableColumn_9.setWidth(100);
		tableColumn_9.setText("\u6536\u8D27\u8981\u6C42");
		tableColumn_9.setToolTipText("confirmTime");

		TableColumn tableColumn_10 = new TableColumn(table, SWT.NONE);
		tableColumn_10.setWidth(100);
		tableColumn_10.setText("\u597D\u8BC4\u5185\u5BB9");
		tableColumn_10.setToolTipText("hpWord");

		TableColumn tableColumn_11 = new TableColumn(table, SWT.NONE);
		tableColumn_11.setWidth(100);
		tableColumn_11.setText("\u5B9D\u8D1D\u5730\u5740");
		tableColumn_11.setToolTipText("tbUrl");
	}

	
	public Task getSelectTask(){
		Task task = null;;
		TableItem[] items = table.getSelection();
		if(items.length > 0){
			task = (Task) items[0].getData();
		}
		return task;
	}
}
